/*
 *  Copyright 2001-2004 The Apache Software Foundation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package ar.uba.fi.posgrado.economy.web.form.customer;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.util.LabelValueBean;

import ar.uba.fi.posgrado.common.model.Address;
import ar.uba.fi.posgrado.economy.model.Customer;
import ar.uba.fi.posgrado.economy.model.CustomerAccount;
import ar.uba.fi.posgrado.economy.model.Terms;

/**
 * Form para {@link Customer Clientes}
 * 
 * @author pablo.tortorella
 */
@SuppressWarnings("serial")
public class CustomerForm extends ActionForm {

	private Long id;

	private String name;

	private String corporateName;

	private String terms;

	private String termTypeSelected = Terms.CONSUMIDOR_FINAL.toStringValue();

	private List<LabelValueBean> termTypeCollection = new ArrayList<LabelValueBean>();

	private String document;

	private String addressStreet;

	private String addressNumber;

	private String addressFloor;

	private String addressRoom;

	private String addressCity;

	private String addressTown;

	private String addressZipCode;

	private CustomerAccount account;

	private String phone;

	private String mobile;

	private String email;

	private String contact;

	private Date registerDate;

	private List<Customer> customers = new ArrayList<Customer>();

	// En caso de ser recibido indica a donde debe ser redireccionado el
	// findForward
	private String redirectTo;

	/**
	 * @return the contact
	 */
	public String getContact() {
		return contact;
	}

	/**
	 * @param contact
	 *            the contact to set
	 */
	public void setContact(String contact) {
		this.contact = contact;
	}

	/**
	 * @return the addressZipCode
	 */
	public String getAddressZipCode() {
		return addressZipCode;
	}

	/**
	 * @param addressZipCode
	 *            the addressZipCode to set
	 */
	public void setAddressZipCode(String addressZipCode) {
		this.addressZipCode = addressZipCode;
	}

	/**
	 * @return the account
	 */
	public CustomerAccount getAccount() {
		return account;
	}

	/**
	 * @param account
	 *            the account to set
	 */
	public void setAccount(CustomerAccount account) {
		this.account = account;
	}

	/**
	 * @param corporateName
	 *            the corporateName to set
	 */
	public void setCorporateName(String corporateName) {
		this.corporateName = corporateName;
	}

	/**
	 * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
	 *      javax.servlet.http.HttpServletRequest)
	 */
	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors actionErrors = new ActionErrors();

		if (this.corporateName.trim().equals("")) {
			actionErrors.add("customer.corporateName", new ActionMessage(
					"customer.corporateName.empty"));
		}
		if (this.name.trim().equals("")) {

			actionErrors.add("customer.name", new ActionMessage(
					"customer.name.empty"));
		}
		if (this.addressCity.trim().equals("")
				|| this.addressTown.trim().equals("")
				|| this.addressStreet.trim().equals("")
				|| this.addressNumber.trim().equals("")) {
			actionErrors.add("customer.address", new ActionMessage(
					"customer.address.empty"));
		}

		return actionErrors;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return this.name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the corporateName
	 */
	public String getCorporateName() {
		return this.corporateName;
	}

	/**
	 * @param corporateName
	 *            the corporateName to set
	 */
	public void setValue(String corporateName) {
		this.corporateName = corporateName;
	}

	/**
	 * @return the customers
	 */
	public List<Customer> getCustomers() {
		return this.customers;
	}

	/**
	 * @param customers
	 *            the customers to set
	 */
	public void setCustomers(List<Customer> customers) {
		this.customers = customers;
	}

	/**
	 * @return the id
	 */
	public Long getId() {
		return this.id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	/**
	 * @return the redirectTo
	 */
	public String getRedirectTo() {
		return this.redirectTo;
	}

	/**
	 * @param redirectTo
	 *            the redirectTo to set
	 */
	public void setRedirectTo(String redirectTo) {
		this.redirectTo = redirectTo;
	}

	/**
	 * @return the document
	 */
	public String getDocument() {
		return document;
	}

	/**
	 * @param document
	 *            the document to set
	 */
	public void setDocument(String document) {
		this.document = document;
	}

	/**
	 * @return the terms
	 */
	public String getTerms() {
		return terms;
	}

	/**
	 * @param terms
	 *            the terms to set
	 */
	public void setTerms(String terms) {
		this.terms = terms;
	}

	/**
	 * @return the addressCity
	 */
	public String getAddressCity() {
		return addressCity;
	}

	/**
	 * @param addressCity
	 *            the addressCity to set
	 */
	public void setAddressCity(String addressCity) {
		this.addressCity = addressCity;
	}

	/**
	 * @return the addressFloor
	 */
	public String getAddressFloor() {
		return addressFloor;
	}

	/**
	 * @param addressFloor
	 *            the addressFloor to set
	 */
	public void setAddressFloor(String addressFloor) {
		this.addressFloor = addressFloor;
	}

	/**
	 * @return the addressNumber
	 */
	public String getAddressNumber() {
		return addressNumber;
	}

	/**
	 * @param addressNumber
	 *            the addressNumber to set
	 */
	public void setAddressNumber(String addressNumber) {
		this.addressNumber = addressNumber;
	}

	/**
	 * @return the addressRoom
	 */
	public String getAddressRoom() {
		return addressRoom;
	}

	/**
	 * @param addressRoom
	 *            the addressRoom to set
	 */
	public void setAddressRoom(String addressRoom) {
		this.addressRoom = addressRoom;
	}

	/**
	 * @return the addressStreet
	 */
	public String getAddressStreet() {
		return addressStreet;
	}

	/**
	 * @param addressStreet
	 *            the addressStreet to set
	 */
	public void setAddressStreet(String addressStreet) {
		this.addressStreet = addressStreet;
	}

	/**
	 * @return the addressTown
	 */
	public String getAddressTown() {
		return addressTown;
	}

	/**
	 * @param addressTown
	 *            the addressTown to set
	 */
	public void setAddressTown(String addressTown) {
		this.addressTown = addressTown;
	}

	/**
	 * @return the registerDate
	 */
	public Date getRegisterDate() {
		return registerDate;
	}

	/**
	 * @param registerDate
	 *            the registerDate to set
	 */
	public void setRegisterDate(Date registerDate) {
		this.registerDate = registerDate;
	}

	public Address getAddress() {
		Address address = new Address();
		address.setCity(getAddressCity());
		address.setFloor(getAddressFloor());
		address.setNumber(getAddressNumber());
		address.setRoom(getAddressRoom());
		address.setStreet(getAddressStreet());
		address.setTown(getAddressTown());
		address.setZipCode(getAddressZipCode());
		return address;
	}

	public void setAddress(Address address) {
		this.setAddressStreet(address.getStreet());
		this.setAddressNumber(address.getNumber());
		this.setAddressFloor(address.getFloor());
		this.setAddressRoom(address.getRoom());
		this.setAddressCity(address.getCity());
		this.setAddressTown(address.getTown());
		this.setAddressZipCode(address.getZipCode());
	}

	/**
	 * @return the termTypeCollection
	 */
	public List<LabelValueBean> getTermTypeCollection() {
		return termTypeCollection;
	}

	/**
	 * @param termTypeCollection
	 *            the termTypeCollection to set
	 */
	public void setTermTypeCollection(List<LabelValueBean> termTypeCollection) {
		this.termTypeCollection = termTypeCollection;
	}

	/**
	 * @return the termTypeSelected
	 */
	public String getTermTypeSelected() {
		return termTypeSelected;
	}

	/**
	 * @param termTypeSelected
	 *            the termTypeSelected to set
	 */
	public void setTermTypeSelected(String termTypeSelected) {
		this.termTypeSelected = termTypeSelected;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email
	 *            the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the mobile
	 */
	public String getMobile() {
		return mobile;
	}

	/**
	 * @param mobile
	 *            the mobile to set
	 */
	public void setMobile(String mobileNumber) {
		this.mobile = mobileNumber;
	}

	/**
	 * @return the phone
	 */
	public String getPhone() {
		return phone;
	}

	/**
	 * @param phone
	 *            the phone to set
	 */
	public void setPhone(String phoneNumber) {
		this.phone = phoneNumber;
	}

}
